

from rest_framework import serializers
from django.contrib.auth.models import Permission,ContentType


# 新建权限可选类型序列化器
class PermTypeModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = ContentType
        fields = [
            'id',
            'name'
        ]


# 权限模型类序列化器
class PermModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Permission
        fields = [
            'id',
            'name',
            'codename', # 识别名, django中一个权限的字符串描述是：`应用名.识别名`
            'content_type' # 权限类型 —— 即权限从属应用
        ]